package com.syncomponents.client.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.listener.SessionAwareMessageListener;

/**
 * 消息监听
 * 
 * @author sunkey
 * @date Jan 15, 2014
 */
public class SynMessageListener implements SessionAwareMessageListener<Message> {

    private final static Logger logger = LoggerFactory.getLogger(SynMessageListener.class);

    private IJmsReceiver<?> jmsReceiver;

    @Override
    public void onMessage(Message message, Session session) throws JMSException {

        if (logger.isDebugEnabled()) {
            logger.debug("receiving message :{}", message.toString());
        }

        Object obj = jmsReceiver.recieve(message);

        jmsReceiver.reply(session, message.getJMSReplyTo(), obj);

    }

    public void setJmsReceiver(IJmsReceiver<?> jmsReceiver) {
        this.jmsReceiver = jmsReceiver;
    }

}
